'use strict';
const uniPush = uniCloud.getPushManager({appId:"__UNI__BA731DF"})
module.exports = {
	/**
	 * 下发直播图片变动
	 * @url client/push/kh/sendLiveChange 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} img  图片路径 https://xxxxx
   * @param {Boolean} watermask 是否添加水印 false
   * @param {String} bgColor 背景色 '#000'
   * @param {String} title 标题 留姓氏我来做~
   * @param {String} titleColor 标题颜色 '#000'
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { push_clientid, img, watermask, bgColor, title, titleColor } = data;
		let res = { code: 0, msg: "" };
    
		// 业务逻辑开始-----------------------------------------------------------
    const pushInfo = await vk.baseDao.findByWhereJson({
      dbName:"user-live-push",
      whereJson: {
        user_id: push_clientid,
      }
    });

    try{
      if (pushInfo) {
        const result = await uniPush.sendMessage({
            "push_clientid": pushInfo.push_client_id,     //填写上一步在uni-app客户端获取到的客户端推送标识push_clientid  
            "title": "通知栏显示的标题",      
            "content": "通知栏显示的内容",  
            "payload": {  
                img,
                watermask,
				bgColor,
				title,
				titleColor
            }
        })
        res.msg = "下发成功"
      } else {
        res = { code: -1, msg: "请用手机扫码" }
      }
    } catch(e) {
      //TODO handle the exception
      res = { code: -1, msg: "下发失败" }
    }

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
